home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.10 Oct 94 / Sprocket / AppSpecific / App.cp next >
Encoding:
Text File  |  1994-08-25  |  3.8 KB  |  235 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        App.cp
  3.  
  4.     Contains:    Boilerplate application-specific code.
  5.                 
  6.     Written by: Dave Falkenburg
  7.  
  8.     Copyright:    © 1993-94 by Dave Falkenburg, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.      
  12.  */
  13.  
  14. #include <Windows.h>
  15. #include <Dialogs.h>
  16. #include <Menus.h>
  17. #include <Desk.h>
  18. #include <Errors.h>
  19. #include <Resources.h>
  20. #include <StandardFile.h>
  21. #include <Devices.h>        //    was <Desk.h>
  22.  
  23. #include "AppLib.h"
  24. #include "Window.h"
  25. #include "StandardMenus.h"
  26. #include "SplashWindow.h"
  27.  
  28. #include "ToolWindow.h"
  29. #include "DocWindow.h"
  30. #include "PreferencesDialogWindow.h"
  31. #include "MailableDocWindow.h"
  32.  
  33. #include "Preferences.h"
  34.  
  35. AppPreferences    gPreferences;
  36.  
  37. //    Function Prototypes:
  38.  
  39. void    AboutBox(void);
  40. void    OpenExistingDocument(void);
  41.  
  42.  
  43. #define    mDebug                            256
  44. #define        iNewMailableWindow            1
  45.  
  46. #define    kAboutBoxFor68K                    256
  47. #define    kAboutBoxForPowerPC                257
  48. #define        iCreditsButton                    2
  49.  
  50. #define    kCreditsBox                        258
  51.  
  52.  
  53. OSErr
  54. SetupApplication(void)
  55.     {    
  56.     InsertMenu(GetMenu(mDebug),0);                //    Add Debug Menu
  57.  
  58.     if (gHasAOCE)
  59.         EnableItem(GetMHandle(mDebug),1);
  60.  
  61.     TToolWindow    * someTools = new TToolWindow(1025);
  62.  
  63.     gPreferences.fMailPreferences.fCreateMailerForNewDocuments = true;
  64.  
  65.     InitCursor();
  66.     return (noErr);
  67.     }
  68.  
  69. void
  70. TearDownApplication(void)
  71.     {
  72.     //    Not much to do yet.
  73.     }
  74.     
  75. void
  76. HandleMenu(TWindow * topWindowObj, long menuCode)
  77.     {
  78.     short    menu = (short) (menuCode >> 16);
  79.     short    item = (short) (menuCode & 0xffff);
  80.     Str255    deskAccName;
  81.     
  82.     switch (menu)
  83.         {
  84.         case    mApple:
  85.             switch (item)
  86.                 {
  87.                 case    iAbout:
  88.                     AboutBox();
  89.                     break;
  90.                     
  91.                 default:
  92.                     GetItem(GetMHandle(mApple),item,deskAccName);
  93.                     (void) OpenDeskAcc(deskAccName);
  94.                     break;
  95.                 }
  96.             break;
  97.             
  98.         case    mFile:
  99.             switch (item)
  100.                 {
  101.                 case    iNew:
  102.                     OpenNewDocument();
  103.                     break;
  104.                 
  105.                 case    iOpen:
  106.                     OpenExistingDocument();
  107.                     break;
  108.                 
  109.                 case    iClose:
  110.                     HandleClose(FrontNonFloatingWindow());
  111.                     break;
  112.                     
  113.                 case    iPreferences:
  114.                     TPreferencesDialogWindow * prefsDialog = new TPreferencesDialogWindow;
  115.                     break;
  116.  
  117.                 case    iQuit:
  118.                     gDone = true;
  119.                     break;
  120.                     
  121.                 default:
  122.                     break;
  123.                 }
  124.             break;
  125.         
  126.         case    mEdit:
  127.             switch (item)
  128.                 {
  129.                 case    iShowOrHideClipboard:
  130.                     break;
  131.                     
  132.                 default:
  133.                     if ((!SystemEdit(item-1)) && (topWindowObj != nil))
  134.                         topWindowObj->DoEditMenu(item);
  135.                     break;
  136.                 }
  137.         
  138.         case    mDebug:
  139.             switch(item)
  140.                 {
  141.                 case    iNewMailableWindow:
  142.                     TMailableDocWindow *aWackyThing = new TMailableDocWindow;
  143.                     break;
  144.                     
  145.                 default:
  146.                     break;
  147.                 }
  148.             break;
  149.             
  150.         default:
  151.             break;
  152.         }
  153.         
  154.     HiliteMenu(0);
  155.     }
  156.  
  157.  
  158. void
  159. AboutBox(void)
  160.     {
  161.     Handle            versionHandle;
  162.     StringPtr        nullStr = (StringPtr) "\p";
  163.     StringPtr        shortVersionString = nullStr;
  164.     short            itemHit;
  165.     
  166.     versionHandle = GetResource('vers',1);
  167.     if (versionHandle)
  168.         shortVersionString = (StringPtr) ((char *) *versionHandle + 6);
  169.     ParamText(shortVersionString,nullStr,nullStr,nullStr);
  170.     ReleaseResource(versionHandle);
  171.  
  172. #ifndef    powerc
  173.     itemHit = StandardAlert(kAboutBoxFor68K);
  174. #else
  175.     itemHit = StandardAlert(kAboutBoxForPowerPC);
  176. #endif
  177.  
  178.     if (itemHit == iCreditsButton)
  179.         StandardAlert(kCreditsBox);
  180.     }
  181.  
  182.  
  183. void
  184. OpenExistingDocument(void)
  185.     {
  186.     StandardFileReply    reply;
  187.     SFTypeList            ourTypes;
  188.     
  189.     Point    where = { -1, -1 };
  190.     
  191.     HiliteWindowsForModalDialog(false);
  192.     CustomGetFile((FileFilterYDUPP) nil, -1, ourTypes, &reply, 0, where,
  193.                   (DlgHookYDUPP) nil,StandardDialogFilterYD, nil,nil,nil);
  194.     HiliteWindowsForModalDialog(true);
  195.     }
  196.  
  197.  
  198. void
  199. ConvertClipboard(void)
  200.     {
  201.     }
  202.  
  203.  
  204. OSErr
  205. OpenNewDocument(void)
  206.     {
  207.     TDocWindow    *aNewWindow = new TDocWindow();
  208.     
  209.     if (aNewWindow)
  210.         return noErr;
  211.     else
  212.         return memFullErr;
  213.     }
  214.  
  215.  
  216. OSErr
  217. OpenDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  218.     {
  219.     return OpenNewDocument();    //    cheat for now…
  220.     }
  221.  
  222.  
  223. OSErr
  224. PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  225.     {
  226.     return noErr;
  227.     }
  228.  
  229.  
  230. Boolean
  231. QuitApplication(void)
  232.     {
  233.     return true;
  234.     }
  235.